<template>
  <div class="Box">
    <div class="course_box" v-for="item in vedioList" :key="item.courseId">
      <div class="img_box">
        <img class="listImg" :src="item.courseImg" v-if="item.courseImg" />
        <img class="listImg" alt="加载失败！" v-else />
      </div>
      <div class="footer">
        <div>
          <div class="name">{{item.coursename}}</div>
          <div class="dixia">
            <div class="examtime">考试时间：{{ item.examtime?item.examtime.split(" ")[0]:"待定" }}</div>
            <div class="bottom">
              <i @click="showPanel(item.courseId)" class="el-icon-arrow-down active"></i>
              <a :href="item.moocLink" target="_blank">开始学习</a>
              <transition name="el-zoom-in-top">
                <div>
                  <ul v-show="show2 && item.courseId===id" class="panel">
                    <li @click="panelItemClick(item.courseId)" class="active">加入学习</li>
                  </ul>
                </div>
              </transition>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { addCourse } from '@/api/course'
export default {
  props: {
    vedioList: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      show2: false,
      id: null
    }
  },
  methods: {
    showPanel(id) {
      this.id = id
      this.show2 = !this.show2
    },
    panelItemClick(courseId) {
      this.show2 = false
      this.addCourseFn(courseId)
    },
    addCourseFn(courseId) {
      const userId = this.$store.state.user.profile.userId
      const data = {
        userId,
        courseId
      }
      addCourse(data).then(res => {
        if (res.data) {
          this.$message({
            type: 'success',
            message: res.msg
          })
        } else {
          this.$message({
            type: 'warning',
            message: res.msg
          })
        }
      })
    }
  }
}
</script>

<style lang="less" scoped>
.Box {
  display: flex;
  flex-wrap: wrap;
  gap: 30px;
}
.course_box {
  background-color: #fff;
  border-radius: 6px;
  padding-bottom: 5px;
  //   overflow: hidden;
}
.img_box {
  position: relative;
  background-color: #eff0f2;
  width: 277px;
  height: 156px;
  img {
    object-fit: fill;
  }
}
.footer {
  padding: 20px 10px;
  padding-bottom: 10px;
  p {
    font-size: 18px;
  }
  .dixia {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 10px;
    .examtime {
      font-size: 10px;
      color: #ccc;
    }
    .bottom {
      position: relative;
      width: 78px;
      height: 24px;
      border: 1px solid #347abb;
      color: #347abb;
      text-align: center;
      line-height: 24px;
      cursor: pointer;
      .active {
        &:active {
          background-color: #347abb;
          color: #fff;
          user-select: none;
        }
      }
    }
  }
}
.panel {
  position: absolute;
  background-color: #ffff;
  width: 100%;
  z-index: 10000;
  border: 1px solid #ccc;
}
</style>

